/* processor.h - Copyright (C) 2014 James Boyle

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
#ifndef PROCESSOR_HEADER_INCLUDED
#define PROCESSOR_HEADER_INCLUDED

/* the user_func struct is a single node in the list of user callback
   functions */
typedef struct user_func
{
	int (*func)(const char);
	struct user_func *next;
	int priority;
} USER_FUNC;

/* the processor struct contains the entire state of the processor, along
   with the dynamic list of callback functions */
typedef struct processor
{
	USER_FUNC *start;
	int func_count;
	/* the timeout function is a function given by the user, that tells the
	   processor if processing has timed out ie samples aren't being
	   generated in time - it should return NO_ERROR if it hasn't timed
	   out, and PROCESSOR_TIMEOUT if it has */
	int (*timeout_function)(void);
} PROCESSOR;

void processor_init(PROCESSOR *const p, int (*tf)(void));
void processor_finish(PROCESSOR *const);
int process(PROCESSOR *const p, const char);
int processor_add_func(PROCESSOR *const p, int (*f)(const char),
                       const int priority);

#endif
